<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Uploads extends CI_Controller {
     function __construct(){
        parent::__construct();
        }
        
/* Upload del logo */
    public function upload_logo(){
        $this->load->library('globals_functions');
        $random = $newpass = $this->globals_functions->random_pass();
        $config['upload_path'] = './images/uploads/logos';
        $upload_path = $config['upload_path'];
        $config['allowed_types'] = 'gif|jpg|png';
	$config['max_size'] = '2048';
        $config['remove_spaces'] = TRUE;
        $config['overwrite'] = FALSE;
        $config['file_name'] = $random;
	$this->load->library('upload', $config);
        if (!$this->upload->do_upload()){
            $error = array('error' => $this->upload->display_errors());
             $this->load->view('admin/v_config',$error);
	}else{
            $dataok = array('upload_data' => $this->upload->data());
                foreach($dataok as $clave => $valor){ 
                     $newimagename = $random.$valor['file_ext'];
                     //Se crea el thumbnail
                     $config['image_library'] = 'GD2';
                     $config['source_image'] = $valor['full_path'];;
                     $config['create_thumb'] = TRUE;
                     $config['thumb_marker'] = '_tn';
                     $config['master_dim'] = 'auto';
                     $config['maintain_ratio'] = TRUE;
                     $config['width'] = 75;
                     $config['height'] = 50;
                     $config['new_image'] = $newimagename;
                     $this->load->library('image_lib', $config);
                      if (!$this->image_lib->resize()){
                        $error = array('error' => $this->image_lib->display_errors());
                        $this->load->view('admin/v_config',$error);
                        }
                     $this->load->model('globals_m');
                     $id_pic = $this->globals_m->insert_pic($upload_path,$dataok);
                     $this->load->model('admin/Config_m');
                     $this->Config_m->update_pic_logo($id_pic);
                     redirect('admin/config');
                    }
		}
        }

/* Upload foto del postulante */
    public function upload_pic_postulante(){
        $this->load->library('globals_functions');
        $random = $newpass = $this->globals_functions->random_pass();
        $config['upload_path'] = './images/uploads/pictures';
        $upload_path = $config['upload_path'];
        $config['allowed_types'] = 'gif|jpg|png';
	$config['max_size'] = '2048';
        $config['remove_spaces'] = TRUE;
        $config['overwrite'] = FALSE;
        $config['file_name'] = $random;
	$this->load->library('upload', $config);
        if (!$this->upload->do_upload()){
            $error = array('error' => $this->upload->display_errors());
             //$this->load->view('admin/v_config',$error);
	}else{
            $dataok = array('upload_data' => $this->upload->data());
                foreach($dataok as $clave => $valor){ 
                     $newimagename = $random.$valor['file_ext'];
                     //Se crea el thumbnail
                     $config['image_library'] = 'GD2';
                     $config['source_image'] = $valor['full_path'];;
                     $config['create_thumb'] = TRUE;
                     $config['thumb_marker'] = '_tn';
                     $config['master_dim'] = 'auto';
                     $config['maintain_ratio'] = TRUE;
                     $config['width'] = 75;
                     $config['height'] = 50;
                     $config['new_image'] = $newimagename;
                     $this->load->library('image_lib', $config);
                      if (!$this->image_lib->resize()){
                        echo $this->image_lib->display_errors();
                        }
                     $this->load->model('globals_m');
                     $id_pic = $this->globals_m->insert_pic($upload_path,$dataok);
                     $this->load->model('admin/Config_m');
                     $this->Config_m->update_pic_logo($id_pic);
                     redirect('admin/config');
                    }
		}
        }
  
}

/***
 * Valores del array data que devuelve al subir la imagen
file_name: foto.jpg
file_type: image/jpeg
file_path: D:/xampp/htdocs/xtudent/images/uploads/logos/
full_path: D:/xampp/htdocs/xtudent/images/uploads/logos/foto.jpg
raw_name: foto
orig_name: foto.jpg
client_name: foto.jpg
file_ext: .jpg
file_size: 16.11
is_image: 1
image_width: 320
image_height: 320
image_type: jpeg
image_size_str: width="320" height="320"
 * 
 * 
 */